﻿using UnityEditor;
using UnityEngine;

[CustomEditor (typeof (MapGenerator))]
public class MapGeneratorEditor : Editor {
    #region 生命周期函数
    public override void OnInspectorGUI () {
        // target是自定义编辑器正在检查的对象
        // target is the object that this custom editor is inspecting
        MapGenerator mapGen = (MapGenerator) target;

        // 绘制默认Inspector
        // 如果面板上有值改变返回值true
        if (DrawDefaultInspector ()) {
            // 如果是改变值时也生成就生成
            if (mapGen.autoUpdate) {
                mapGen.DrawMapInEditor ();
            }
        }
        
        // 点下Generate按钮就生成
        if (GUILayout.Button ("Generate")) {
            mapGen.DrawMapInEditor ();
        }
    }
    #endregion
}